package com.ntschy.bt.service.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ntschy.bt.entity.dataobject.BtPolicy;
import com.ntschy.bt.entity.enums.btpolicyEnum.BtPolicyAuditStatusEnum;
import com.ntschy.bt.entity.enums.btpolicyEnum.BtPolicyStatusEnum;
import com.ntschy.bt.mapper.BtPolicyMapper;
import com.ntschy.bt.service.IBtPolicyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 政策信息 服务实现类
 * </p>
 *
 * @author cm
 * @since 2020-12-28
 */
@Service
public class BtPolicyServiceImpl implements IBtPolicyService {

    @Autowired
    private BtPolicyMapper btPolicyMapper;

    // * ================================================基础增删改查BEGIN============================================= *

    /**
     * 分页查询政策信息
     * 当前查询条件：
     * @param btPolicy 政策信息列表
     * @return 政策信息列表查询
     */
    @Override
    public List<BtPolicy> pageBtPolicy(BtPolicy btPolicy) {
        return btPolicyMapper.pageBtPolicy(btPolicy);
    }




    /**
     * 新增政策
     * @param btPolicy 供需新增政策
     * @return 新增结果
     */
    @Override
    public int addBtPolicy(BtPolicy btPolicy) {
        btPolicy.setId(IdUtil.fastUUID());
        return btPolicyMapper.insert(btPolicy);
    }

    /**
     * 更新政策
     * @param btPolicy 供需政策对象
     * @return 更新结果
     */
    @Override
    public int updateBtPolicy(BtPolicy btPolicy) {
        return btPolicyMapper.updateById(btPolicy);
    }

    /**
     * 删除政策信息
     * @param id 供需政策ID
     * @return 删除结果
     */
    @Override
    public int deleteBtPolicy(String id) {
        return btPolicyMapper.deleteById(id);
    }

    /**
     * 查询政策信息
     * @param id 供需政策ID
     * @return 查询结果
     */
    @Override
    public BtPolicy selectBtPolicy(String id ) {
        return btPolicyMapper.selectBtPolicy(id);
    }


    /**
     * 政策详情列表信息
     * @param btPolicy 政策详情列表信息
     * @return 政策详情列表信息
     */
    @Override
    public List<BtPolicy> pageBtPolicyAudit(BtPolicy btPolicy) {
        return btPolicyMapper.pageBtPolicyAudit(btPolicy);
    }

    @Override
    public BtPolicy selectBtPolicyInfoById(String id){
        return btPolicyMapper.selectById(id);
    }

    @Override
    public int updateAduitPolicy(BtPolicy btPolicy) {
        if (btPolicy.getExamineResult() == BtPolicyAuditStatusEnum.getBtPolicyAuditStatusEnumValue(1)){
            btPolicy.setExamineResult(BtPolicyAuditStatusEnum.TO_PAST);
        }
        if (btPolicy.getExamineResult() == BtPolicyAuditStatusEnum.getBtPolicyAuditStatusEnumValue(2)){
            btPolicy.setExamineResult(BtPolicyAuditStatusEnum.TO_BACK);
        }
        return btPolicyMapper.updateById(btPolicy);
    }


    // * =================================================基础增删改查END============================================== *
}
